package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.DailyComment;
import cn.wolfcode.trip.base.mapper.DailyCommentMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IDailyCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DailyCommentServiceImpl implements IDailyCommentService {
    @Autowired
    private DailyCommentMapper dailyCommentMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<DailyComment> list = dailyCommentMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    /**
     * 保存日报评论
     * @param dailyComment
     */
    @Override
    public void save(DailyComment dailyComment) {
        dailyComment.setCreateTime(new Date());
        dailyCommentMapper.insert(dailyComment);
    }

    @Override
    public int getCount(Long dailyId) {
        return dailyCommentMapper.getCountByDailyId(dailyId);
    }

    @Override
    public DailyComment getContentById(Long id) {
        return dailyCommentMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delete(Long id) {
        dailyCommentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo queryAdmin(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<DailyComment> list = dailyCommentMapper.selectForList2(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<DailyComment> getDailyCommentById(Long dailyId) {
        return dailyCommentMapper.getDailyCommentById(dailyId);
    }
}
